require.config({
    paths: {
        "jquery": "/public/vendor/jquery.min",
        "jquery-migrate": "/public/vendor/jquery-migrate/jquery-migrate",
        "scrollTo":"/public/vendor/jquery-scrollto/jquery.scrollTo"
    }
});
var snow_pack_ing = [
    {
        title: "",
        image: "app/images/pack00/photo00.jpg",
        wordLine: ["魅力无穷的滑雪季节已悄然离去，室外雪场都已郁郁葱葱，而乔波室内滑雪场内依旧白雪皑皑，无论春、夏、秋、冬这里的魔毯、拖牵、滑道、跳台、乐园都常年开放，是雪友夏季滑雪的最佳去处。"]
    },
    {
        title: "",
        image: "app/images/pack00/photo01.jpg",
        wordLine: ["乔波麦罗公园作为四季的训练基地性质，坐落在乔波室内滑雪场里，这一季的公园里将包括一个跳台和8个道具，以及新增设的初级公园将在初级雪道上为初级滑雪爱好者准备了连包和迷你道具箱，供大家提高技巧！"]
    },
    {
        title: "",
        image: "app/images/pack00/photo02.jpg",
        wordLine: ["麦罗公园内的设施有：轮胎；closeup rail ；up bar / 4m；flat down tube / 8m；flat barrel / 6m；flat down box / 9m；down rail / 6m；跳台/ 5m；大桶"]
    },
    {
        title: "",
        image: "app/images/pack00/photo03.jpg",
        wordLine: ["除了滑雪，乔波的夏季活动十分丰富，最近，全国雪地摩托车锦标赛也在乔波举办了新闻发布会，该活动旨在通过全国雪地摩托锦标赛、摩托车越野赛及汽车相关活动，以及全国范围自驾穿行雪域，吸引更多人关注冰雪运动，以实际行动参与到申冬奥事业中；"]
    }
];


var snow_pack_image = []

var PACK = {
    data: undefined
}

var PACK_ING = {
    index: 0,

    mapIndex: 0
}

require(['jquery', 'scrollTo'], function ($, scrollTo) {

    scrollTo.init($);

    // init start
    PACK_ING.index = 0;
    // init end

    for (var i in [0, 1, 2, 3, 4]) {
        $("#snow-tab-" + i).click(function () {
            var index = $(this).attr("_i");
            snowTabClick(Number(index));
            setSnowPack(Number(index));
        });

        $("#a-snow-tab-" + i).click(function () {
            var index = $(this).attr("_i");
            snowTabClick(Number(index));
            setSnowPack(Number(index));
        });


    }

    function setSnowPackIng() {
        var info = snow_pack_ing[PACK_ING.index];
        $("#snow-content-thumb-img").attr("src", info.image);
        $("#snow-content-word").html("");
        $("#snow-content-title").html(info.title);

        $("#snow-content-word").append("<p>" +
            info.wordLine.join("") +
            "</p>");
    }

    function getPackIndex(direction) {
        if (direction == "left") {
            PACK_ING.index = PACK_ING.index - 1;
        } else {
            PACK_ING.index = PACK_ING.index + 1;
        }

        if (PACK_ING.index < 0) {
            PACK_ING.index = snow_pack_ing.length - 1;
        }

        if (PACK_ING.index > snow_pack_ing.length - 1) {
            PACK_ING.index = 0;
        }
        console.log("PACK_ING.index:" + PACK_ING.index);
        return PACK_ING.index;
    }

    $("#ctrl-left").click(function () {

        console.log("滑雪进行时 left");
        setSnowPackIng(getPackIndex("left"));
    });

    $("#ctrl-right").click(function () {
        console.log("滑雪进行时 right");
        setSnowPackIng(getPackIndex("right"));
    });

    $(".snow-item-box").mouseover(function () {
        $(this).removeClass("snow-item-box-grep");
        $(this).find(".snow-item-box-left").eq(0).removeClass("snow-item-box-grep");
    });

    $(".snow-item-box").mouseleave(function () {
        $(this).addClass("snow-item-box-grep");
        $(this).find(".snow-item-box-left").eq(0).addClass("snow-item-box-grep");
    });

    $(window).scroll(function () {
        console.log($(window).scrollTop())
        if (582 < $(window).scrollTop()) {
            $("#snow-menu").fadeIn();
        } else {
            $("#snow-menu").hide();
        }
    });

    $(window).resize(function () {
        var left = $(".snow-ski-ing-box").offset().left;
        left = left + 1010;
        $("#snow-menu").css("left", left + "px");
    });

    function iniSnowMenu() {

        var left = $(".snow-ski-ing-box").offset().left;
        left = left + 1010;
        $("#snow-menu").css("left", left + "px");

        if (582 < $(window).scrollTop()) {
            $("#snow-menu").fadeIn();
        } else {
            $("#snow-menu").hide();
        }
    }

    (function initData() {
        $.ajax({
            url: "pack.json",
            success: function (data) {
                PACK.data = data;
                setSnowPack(0);
            }
        });
    })();

    iniSnowMenu();


    function setSnowPack(id) {
        var _data = PACK.data[id]

        //set 滑雪进行时
        var newsList = _data.newsList;
        snow_pack_ing = newsList;
        setSnowPackIng();
        //set 雪场图片

        $("#snow-thumb-box").html("");
        var tpl = '<div class="snow-thumb-box-item"> \
                        <img src="app/images/ui-snow-images-thumb.jpg" width="230" height="150"> \
                   </div>';

        $("#snow-thumb-box").append(tpl);

        var imageList = _data.imageList;
        for (var i = 0; i < imageList.length; i++) {
            var tpl = '<div class="snow-thumb-box-item">' +
                '<a data-lightbox="example-set" data-title="' + imageList[i].title + '" href="' + imageList[i].url + '">' +
                '<img src="' + imageList[i].url + '" width="230" height="150">' +
                '</a>' +
                '</div>';

            $("#snow-thumb-box").append(tpl);
        }
        var desList = _data.desList;
        $("#snow-description-box").html("");
        for (var i = 0; i < desList.length; i++) {

            var tpl = ' \
            <div class="snow-item-box snow-item-box-grep">\
                <div class="snow-item-box-left snow-item-box-grep">\
                    <div class="snow-item-box-content-title">' + desList[i].title + '</div>\
                    <div class="snow-item-box-content">\
                    <p>Google 翻译是一项免费的翻译服务，可提供 64 种语言之间的即 时翻译。它可以在所支持的任意两种语言之间进行字词、 副本</p>\
                    <p>Google 翻译是一项免费的翻译服务，可提供 64 种语言之间的即 时翻译。它可以在所支持的任意两种语言之间进行字词、 副本</p>\
                    </div>\
                </div>\
                <div class="snow-item-box-right">\
                    <img src="' + desList[i].image + '">\
                </div>\
            </div>';

            $("#snow-description-box").append(tpl);

        }

        $(".snow-item-box").mouseover(function () {
            $(this).removeClass("snow-item-box-grep");
            $(this).find(".snow-item-box-left").eq(0).removeClass("snow-item-box-grep");
        });

        $(".snow-item-box").mouseleave(function () {
            $(this).addClass("snow-item-box-grep");
            $(this).find(".snow-item-box-left").eq(0).addClass("snow-item-box-grep");
        });
        //set 雪场简介
    }

    $("#right-welcome").click(function () {
        $.scrollTo('#to-welcome', 500);
    });

    $("#right-sking").click(function () {
        $.scrollTo('#to-sking', 500);
    });

    $("#right-ski-image").click(function () {
        $.scrollTo('#to-ski-image', 500);
    });

    $("#right-ski-des").click(function () {
        $.scrollTo('#to-ski-des', 500);
    });

    $("#right-ski-contact").click(function () {
        $.scrollTo('#to-ski-contact', 500);
    });

    var contactDDList = $("#snow-contact-us-list").find("dd");

    $("#snow-contact-us-active-map").attr("src", "app/images/map/" + PACK_ING.mapIndex + ".jpg");
    for (var i = 0; i < contactDDList.length; i++) {
        var contactListLeft = $("#snow-contact-us-list").offset().left;
        $("#contact-" + i).mouseenter(function () {
            var fixLeft = $(this).offset().left - contactListLeft + 50;
            $("#snow-contact-us-active").stop().animate({"left": fixLeft + "px"}, 400, function () {
                console.log("done");
            });
            var index = $(this).attr("_i");

            $("#snow-contact-us-active-map").attr("src", "app/images/map/" + index + ".jpg");
            console.log($(this).attr("id"));
            console.log($(this).offset());
            console.log("index:" + index);
        });
    }


});

function snowTabClick(index) {
    var ddList = $("#snow-tab").find("dd");
    for (var i = 0; i < ddList.length; i++) {
        $(ddList[i]).removeClass("tab-active");
        if (i == index) {
            $(ddList[i]).addClass("tab-active");
        }
    }
}